//
//  MainTableViewCell.m
//  CoJellyCartoon
//
//  Created by kingbw on 16/4/1.
//  Copyright © 2016年 CJG. All rights reserved.
//

#import "MainTableViewCell.h"

@implementation MainTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.numberLabel = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.numberLabel.textAlignment = NSTextAlignmentCenter;
        self.numberLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.numberLabel];
        
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:self.imgView];
        
        self.title = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.title.numberOfLines = 2;
        self.title.font = [UIFont systemFontOfSize:16];
        [self addSubview:self.title];
        
        self.up = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.up.image = [UIImage imageNamed:@"upzhu"];
        [self addSubview:self.up];
        
        self.upName = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.upName.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.upName];
        
        self.play = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.play.image = [UIImage imageNamed:@"bofang"];
        [self addSubview:self.play];
        
        self.playCount = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.playCount.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.playCount];
        
        self.comment = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.comment.image = [UIImage imageNamed:@"pinglun"];
        [self addSubview:self.comment];
        
        self.commentCount = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.commentCount.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.commentCount];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.numberLabel.frame = CGRectMake(0, ScreenHeight*30/736, ScreenWidth*30/414, ScreenHeight*60/736);
    self.imgView.frame = CGRectMake(ScreenWidth*40/414, ScreenHeight*10/736, ScreenWidth*150/414, ScreenHeight*110/736);
    self.title.frame = CGRectMake(ScreenWidth*195/414, 0, ScreenHeight*200/736, ScreenHeight*80/736);
    self.up.frame = CGRectMake(ScreenWidth*195/414, ScreenHeight*75/736, ScreenWidth*20/414, ScreenHeight*16/736);
    self.upName.frame = CGRectMake(ScreenWidth*215/414, ScreenHeight*73/736, ScreenWidth*180/414, ScreenHeight*20/736);
    self.play.frame = CGRectMake(ScreenWidth*195/414, ScreenHeight*100/736, ScreenWidth*20/414, ScreenHeight*16/736);
    self.playCount.frame = CGRectMake(ScreenWidth*215/414, ScreenHeight*100/736, ScreenWidth*60/414, ScreenHeight*20/736);
    self.comment.frame = CGRectMake(ScreenWidth*290/414, ScreenHeight*100/736, ScreenWidth*20/414, ScreenHeight*16/736);
    self.commentCount.frame = CGRectMake(ScreenWidth*310/414, ScreenHeight*100/736, ScreenWidth*50/414, ScreenHeight*20/736);
}

- (void)setSearch:(SearchModel *)search {
    _search = search;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:search.pic] placeholderImage:[UIImage imageNamed:@"zhanweiye"]];
    
    self.upName.text = search.author;
    self.title.text = search.title;
    
    self.playCount.text = [NSString stringWithFormat:@"%@", search.play.floatValue > 10000 ? [NSString stringWithFormat:@"%0.1f万", (search.play.floatValue / 10000.0)] : search.play];
    
    self.commentCount.text = [NSString stringWithFormat:@"%@", search.video_review.floatValue > 10000 ? [NSString stringWithFormat:@"%0.1f万", (search.video_review.floatValue / 10000.0)]:search.video_review];
}

@end
